package org.korifey.ffbdd.impl;

import org.korifey.ffbdd.api.IBddBackend;
import org.korifey.ffbdd.api.INode;
import org.korifey.ffbdd.api.INonterminal;


public class NonterminalImpl extends NodeImpl implements INonterminal {
	int var;
	int one;
	int zero;
	IBddBackend backend;	
	
	
	public NonterminalImpl(int var, int one, int zero, IBddBackend backend) {
		this(var, one, zero, backend, 0);
	}
	
	public NonterminalImpl(int var, int one, int zero, IBddBackend backend, int index) {
		super();
		this.var = var;
		this.one = one;
		this.zero = zero;
		this.backend = backend;
		setIndex(index);
	}
	
	public int oneIndex() {
		return one;
	}
	
	public int zeroIndex() {
		return zero;
	}
	
	public INode one() {
		return backend.getNode(one);
	}
	public int var() {
		return var;
	}
	public INode zero() {
		return backend.getNode(zero);
	}
	public boolean isTerm() {
		return false;
	}
	
	public void setMark(boolean mark) {
		super.setMark(mark);
		backend.setMark(getIndex(), mark);
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + one;
		result = prime * result + var;
		result = prime * result + zero;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		NonterminalImpl other = (NonterminalImpl) obj;
		if (one != other.one)
			return false;
		if (var != other.var)
			return false;
		if (zero != other.zero)
			return false;
		return true;
	}
	
	
	
	
}
